package com.heima.schedule.client;

import com.heima.apis.schedule.IScheduleClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.schedule.dto.Task;
import com.heima.schedule.service.TaskService;
import com.heima.schedule.service.TaskinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/task")
public class ScheduleClient implements IScheduleClient {

    @Autowired
    private TaskService taskService;


    @Override
    @PostMapping("/add")
    public ResponseResult addTask(Task task) {

        return ResponseResult.okResult(taskService.addTask(task));
    }

    @Override
    @GetMapping("/cancel/{taskId}")
    public ResponseResult cancelTask(long taskId) {
        return ResponseResult.okResult(taskService.cancelTask(taskId));
    }

    @Override
    @GetMapping("/poll")
    public ResponseResult poll() {
        return ResponseResult.okResult(taskService.poll());
    }
}
